# 直接在命令行中构造JSON数据并发送请求
$ErrorActionPreference = "Stop"

# 直接构造JSON字符串，避免任何潜在的解析问题
$jsonBody = '{"title":"测试标题直接发送","content":"测试内容直接发送","sourceUrl":"http://example.com/direct","categoryId":"1"}'

Write-Host "准备发送请求..."
Write-Host "请求数据: $jsonBody"

# 使用.NET WebClient类发送请求，这是最基本的HTTP请求方式
try {
    $webClient = New-Object System.Net.WebClient
    $webClient.Headers.Add("Content-Type", "application/json")
    $response = $webClient.UploadString("http://localhost:8899/api/saveToMaterial", "POST", $jsonBody)
    Write-Host "请求成功"
    Write-Host "响应内容: $response"
} catch {
    Write-Host "请求失败: $($_.Exception.Message)"
} finally {
    $webClient.Dispose()
}